﻿package MyUI{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	public class MyFrame extends Sprite{
		var layout:String;
		var header:Sprite;
		public var content:MyContainer;
		public var title:TextField;
		var cancel:Sprite;
		var contentWidth:Number;
		public function MyFrame(parent = null){
			visible = false;
			if(parent)parent.addChild(this);
			header = new Sprite();
			content = new MyContainer();
			addChild(header);
			addChild(content);
			title = new TextField();
			title.selectable = false;
			title.height = 20;
			header.addChild(title);
			cancel = new Sprite();
			cancel.graphics.lineStyle(2);
			cancel.graphics.lineTo(8,8);
			cancel.graphics.moveTo(8,0);
			cancel.graphics.lineTo(0,8);
			cancel.graphics.lineStyle(2,0,0);
			cancel.graphics.drawRect(0,0,8,8);
			cancel.addEventListener(MouseEvent.CLICK,hidden);
			cancel.hitArea = cancel;
			header.addChild(cancel);
		}
		public function setSize(w:Number,h:Number):void{
			
			graphics.lineStyle(2,0xC0C0C0) ;
			graphics.beginFill(0xF3F3F3);
			graphics.drawRoundRect(0,0,w,h,10);
			graphics.endFill();
			
			header.x = 5;header.y = 5;
			var matrix:Matrix = new Matrix()
			matrix.createGradientBox(w-10,20,Math.PI/2)
			header.graphics.lineStyle(1,0xC0C0C0);
			header.graphics.beginGradientFill(GradientType.LINEAR,[0xFFFFFF,0xDDDDDD,0xFFFFFF],[1,1,1],[0,64,255],matrix);
			header.graphics.drawRect(0,0,w - 10,20);
			header.graphics.endFill();
			header.addEventListener(MouseEvent.MOUSE_DOWN,onStartDrag);
			header.addEventListener(MouseEvent.MOUSE_UP,onStopDrag);
			header.addEventListener(MouseEvent.MOUSE_OUT,onStopDrag);
			cancel.x = w - 22;
			cancel.y = 6;
			contentWidth = w - 10;
			content.x = header.x;
			content.y = header.height+10;
		}
		public function append(...arg){
			for(var i:int = 0;i < arg.length;i++){
				content.append(arg[i])
			}
		}
		public function show(e = null){
			visible = true;
		}
		public function hidden(e = null){
			visible = false;
		}
		function onStartDrag(e:MouseEvent){
			startDrag();
		}
		function onStopDrag(e:MouseEvent){
			stopDrag();
		}
	}
}